<template>
	<view class="body">		
		<view class="search-box">
			<input type="text" placeholder="请输入或扫描发货单" class="search-input" v-model="code" @confirm="doByInput" confirm-type="search"/>
			<view class="search-btn" @tap="doByInput">
				<image src="../../static/icons/icon_search2.png" class="btn-icon"></image>
			</view>
		</view>
		<v-table :columns="columns" :list="listData" :showIndex="true" :row-class-name="rowClassNameFn"></v-table>	
	</view>
</template>

<script>
	import SCan from 'common/scan.js'
	import vTable from '../../components/tablewithindex.vue'
	 
	export default {
		components:{
			vTable
		},
		data() {
			return {
				code:'',
				listData:[],
				columns: [
					{
						title: '发货顺序',
						key: 'salesndt_id',
						$width:"60px"
					},
					{
						title: '物料编号',
						key: 'part_id'
					},
					{
						title: '条码',
						key: 'part_code',
						$width:"220px"
					},
					{
						title: 'BOX',
						key: 'part_packseq',
						$width:"60px"
					}
				]
			}
		}, 
		onShow: function(){
		    SCan.initScan(this.queryAndScan) 
		    SCan.startScan();  
		},  
		onHide:function(){  
		    SCan.stopScan();  
		},  
		onUnload:function(){
		    SCan.stopScan();
		}, 
		onPullDownRefresh:function(){
			this.reDoInput();
			 uni.stopPullDownRefresh()//关闭下拉刷新  
		},
		methods: {
			rowClassNameFn(row,index){
				if(row.part_code==null || row.part_code=='null'){
					return 'hightlight';
				}
			},
			doByInput(e){
				var _this=this;
				_this.queryAndScan(_this.code)
			},
			queryAndScan(code){
				var _this=this;
				_this.code=code;
				if(_this.code!=""){	
					//判定此用户是否具有当前货位权限
					var date=new Date();
					_this.$config.SysConfig.TODAY_SCAN.push({
						page:'扫码明细',
						code:code,
						date:date.getHours()+':'+date.getMinutes()+":" +date.getSeconds()
					})
					
					if(_this.$config.SysConfig.APP_ISONLINE){		
						//在线
						_this.$common.isWifiExec(()=>{
							// console.log(_this.SALESND_ID)
							uni.showLoading({
								title: '数据读取中...'
							});
							//出库单不存在先扫出库单
							var param={
								barcode:_this.code.replace(/[\r\n]/g,"")
							}
							_this.$http.salesendscan(param).then(res=>{
								if(res.code=='1'){			
									var array=res.data;
									if(array.length>0){
										this.listData=array
										uni.hideLoading()
									}
									else{
										uni.showToast({
											title:_this.$config.msgs.nodata,
											icon:'none',
											duration:1500
										})
										// _this.$common.playErrBeep(1);
									}
								}
								else{										
									_this.$common.playErrBeep(1);
									SCan.stopScan();
									uni.showModal({
										title:'提醒',
										content:res.msg,
										showCancel:false,
										success: (resp) => {
											if(resp.confirm){
												SCan.startScan();
											}
										}
									})
								}
							})
						},()=>{
							// _this.$common.playErrBeep(1);
							// uni.showToast(_this.$config.msgs.needwifi)
							uni.showToast({
								title:_this.$config.msgs.needwifi,
								icon:'none',
								duration:1500
							})
						})
					}
					else
					{ //离线 无法查询
						// _this.$common.playErrBeep(1);
						// uni.showToast(_this.$config.msgs.needonline)
						uni.showToast({
							title:_this.$config.msgs.needonline,
							icon:'none',
							duration:1500
						})
					}
				}
				else {
					// _this.$common.playErrBeep(1);
					console.log('err')
				}
			}
		}
	}
</script>

<style>
.body{
	border-top: solid 1px #DBDBDA;
	padding: 0 5upx;
}
.input{
	width: 100%;
	height: 85upx;
	padding-right: 80upx;
	background: url('../../static/icons/qrcode.png') no-repeat scroll right center transparent;
}
.menu-wrapper{
	flex-direction: row;
	display: flex;
	padding:0 40upx;
}
/* .divider{
	border-bottom: solid 4upx #ADADAD;
	height: 1upx;
	margin: 10upx 0upx;
} */
.menu-wrapper .btn-wrapper{
	padding: 10upx 5upx 10upx 5upx;
	width: 100%;
}
.item-container{
	padding: 5upx 15upx 15upx 15upx;	
	background-color: #f4f4f4;
	color: #444;
	border-color: #ddd;
	margin-top: 10upx;
	border-radius: 10upx;
}
.item-container.red{
	padding: 5upx 15upx 15upx 15upx;	
	background-color: #BD362F;
	color:#FFFFFF;
	border-color: #a9302a;
	border-radius: 10upx;
	margin-top: 10upx;
}
.info-content{
	padding: 10upx 15upx;
}
.flexed{
	display: flex;
	flex-direction: row;
	justify-content: center;
	
}
.flexbtn-change{
	flex-grow: 3;
}
.flexbtn-refresh{
	flex-grow: 1;
	margin-left: 15upx;
}
.search-box {
    display: flex;
	flex-direction: row;
	padding: 0upx 15upx;
}
.search-input {
   flex-grow: 11;
   height: 75upx;
   line-height: 80upx;
}
.search-btn {
    flex: 1;
	border: none;	
	padding: 10upx 10upx 5upx 10upx;
}
.btn-icon{
	width: 60upx;
	height: 60upx;
	line-height: 80upx;
}
.divider{
	border-top: solid 4upx #ADADAD;
	height: 1upx;
}
</style>
